<?php echo $header; ?>
<script type="text/javascript">
//-----------------------------------------
// Confirm Actions (delete, uninstall)
//-----------------------------------------
$(document).ready(function(){    	
    // Confirm Uninstall
    $('a').click(function(){
        if ($(this).attr('href') != null && $(this).attr('href').indexOf('install_sample', 1) != -1) {
            if (!confirm('<?php echo $text_confirm; ?>')) {
                return false;
            }
        }
    });
});
</script>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
    <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
<?php echo $shortcut_route;?> 
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/setting.png" alt="" /> <?php echo $heading_title; ?></h1>
     
    </div>
    <div class="content">
    
     <?php echo $shortcut_module;?> 
      
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form" name="form">
      <input type="hidden" name="config_news_installed" value="<?php echo $config_news_installed;?>" />
      <input type="hidden" name="config_news_sample_installed" value="<?php echo $config_news_sample_installed;?>" />
     <table id="author_module" class="form" style="border-collapse: collapse;width: 100%;border: 1px solid #ddd;margin-bottom: 20px;">
          <thead>
            <tr style="background-color: rgb(244, 244, 248);">             
              <td align="right" style="padding: 7px;border-bottom: 1px solid #ddd;">
      <?php if(!$this->config->get('config_news_sample_installed')){?>
       <div class="buttons"><span style="margin-top:5px;"><?php echo $button_sample; ?>:</span> 
      <a href="<?php echo $sample; ?>" class="button"><span>Yes</span></a>      
      <a href="<?php echo $hide_sample; ?>" class="button"><span>No</span></a>
      </div>
      <?php }else{?>
      <div class="buttons">
      <a onclick="$('#form').submit();" class="button"><span><?php echo $button_save; ?></span></a>
      <a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a></div>
       <?php }?>
      </td>
            </tr>
          </thead>
          <tbody>
            <tr>
            <td> 
            
        <h2><?php echo $text_description;?></h2>
        <table class="form">
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_description_limit; ?></td>
              <td>
      <input type="number" name="article_description_limit" value="<?php echo $article_description_limit; ?>" size="5" nKeyPress="if((event.keyCode< 48)|| (event.keyCode > 57)) event.returnValue =false"/>
                <?php if ($error_article_description_limit) { ?>
                <span class="error"><?php echo $error_article_description_limit; ?></span>
                <?php } ?></td>
            </tr>
         </table>
         <h2><?php echo $text_date_format;?> </h2>
         
        <table class="form">
            <tr>
              <td><?php echo $entry_article_date_format; ?></td>
              <td>
         <select name="date_format">
                  <?php if ($config_article_date_format == 'd/m/Y') { ?>
                  <option value="d/m/Y" selected="selected">d/m/Y</option>
                  <?php } else { ?>
                  <option value="d/m/Y">d/m/Y</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd/m/Y h:i:s') { ?>
                  <option value="d/m/Y h:i:s" selected="selected">d/m/Y h:i:s</option>
                  <?php } else { ?>
                  <option value="d/m/Y h:i:s">d/m/Y h:i:s</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd/m/Y h:i:s A') { ?>
                  <option value="d/m/Y h:i:s A" selected="selected">d/m/Y h:i:s A</option>
                  <?php } else { ?>
                  <option value="d/m/Y h:i:s A">d/m/Y h:i:s A</option>
                  <?php } ?>
                  
                  <?php if ($config_article_date_format == 'd-m-Y') { ?>
                  <option value="d-m-Y" selected="selected">d-m-Y</option>
                  <?php } else { ?>
                  <option value="d-m-Y">d-m-Y</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd-m-Y h:i:s') { ?>
                  <option value="d-m-Y h:i:s" selected="selected">d-m-Y h:i:s</option>
                  <?php } else { ?>
                  <option value="d-m-Y h:i:s">d-m-Y h:i:s</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd-m-Y h:i:s A') { ?>
                  <option value="d-m-Y h:i:s A" selected="selected">d-m-Y h:i:s A</option>
                  <?php } else { ?>
                  <option value="d-m-Y h:i:s A">d-m-Y h:i:s A</option>
                  <?php } ?>
                  
                  <?php if ($config_article_date_format == 'd M Y') { ?>
                  <option value="d M Y" selected="selected">d M Y</option>
                  <?php } else { ?>
                  <option value="d M Y">d M Y</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd M Y h:i:s') { ?>
                  <option value="d M Y h:i:s" selected="selected">d M Y h:i:s</option>
                  <?php } else { ?>
                  <option value="d M Y h:i:s">d M Y h:i:s</option>
                  <?php } ?>                  
                  <?php if ($config_article_date_format == 'd M Y h:i:s A') { ?>
                  <option value="d M Y h:i:s A" selected="selected">d M Y h:i:s A</option>
                  <?php } else { ?>
                  <option value="d M Y h:i:s A">d M Y h:i:s A</option>
                  <?php } ?>
                  
                  <?php if ($config_article_date_format == 'd-M-Y') { ?>
                  <option value="d-M-Y" selected="selected">d-M-Y</option>
                  <?php } else { ?>
                  <option value="d-M-Y">d-M-Y</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'd-M-Y h:i:s') { ?>
                  <option value="d-M-Y h:i:s" selected="selected">d-M-Y h:i:s</option>
                  <?php } else { ?>
                  <option value="d-M-Y h:i:s">d-M-Y h:i:s</option>
                  <?php } ?>                  
                  <?php if ($config_article_date_format == 'd-M-Y h:i:s A') { ?>
                  <option value="d-M-Y h:i:s A" selected="selected">d-M-Y h:i:s A</option>
                  <?php } else { ?>
                  <option value="d-M-Y h:i:s A">d-M-Y h:i:s A</option>
                  <?php } ?>
                  
                  
                  <?php if ($config_article_date_format == 'Y/m/d') { ?>
                  <option value="Y/m/d" selected="selected">Y/m/d</option>
                  <?php } else { ?>
                  <option value="Y/m/d">Y/m/d</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'Y/m/d h:i:s') { ?>
                  <option value="Y/m/d h:i:s" selected="selected">Y/m/d h:i:s</option>
                  <?php } else { ?>
                  <option value="Y/m/d h:i:s">Y/m/d h:i:s</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'Y/m/d h:i:s A') { ?>
                  <option value="Y/m/d h:i:s A" selected="selected">Y/m/d h:i:s A</option>
                  <?php } else { ?>
                  <option value="Y/m/d h:i:s A">Y/m/d h:i:s A</option>
                  <?php } ?>
                  
                                    <?php if ($config_article_date_format == 'Y-m-d') { ?>
                  <option value="Y-m-d" selected="selected">Y-m-d</option>
                  <?php } else { ?>
                  <option value="Y-m-d">Y-m-d</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'Y-m-d h:i:s') { ?>
                  <option value="Y-m-d h:i:s" selected="selected">Y-m-d h:i:s</option>
                  <?php } else { ?>
                  <option value="Y-m-d h:i:s">Y-m-d h:i:s</option>
                  <?php } ?>
                  <?php if ($config_article_date_format == 'Y-m-d h:i:s A') { ?>
                  <option value="Y-m-d h:i:s A" selected="selected">Y-m-d h:i:s A</option>
                  <?php } else { ?>
                  <option value="Y-m-d h:i:s A">Y-m-d h:i:s A</option>
                  <?php } ?>
                  
                </select> <input type="text" name="config_article_date_format" value="<?php echo $config_article_date_format;?>" size="10" style="color:#f00;"/></td>
                <script type="text/javascript"><!--
			$('select[name=\'date_format\']').bind('change', function() {
			var format=this.value;
				$('input[name=\'config_article_date_format\']').val(format);
			});
			
			//$('select[name=\'date_format\']').trigger('change');
			//--></script> 
            </tr>
         </table>
                
        <h2><?php echo $text_image_size;?></h2>
            <table class="form">
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_category; ?></td>
              <td><input type="text" name="config_article_category_width" value="<?php echo $config_article_category_width; ?>" size="3" />
                x
                <input type="text" name="config_article_category_height" value="<?php echo $config_article_category_height; ?>" size="3" />
                <?php if ($error_image_article_category) { ?>
                <span class="error"><?php echo $error_image_article_category; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $entry_image_article; ?></td>
              <td><input type="text" name="config_image_article_width" value="<?php echo $config_image_article_width; ?>" size="3" />
                x
                <input type="text" name="config_image_article_height" value="<?php echo $config_image_article_height; ?>" size="3" />
                <?php if ($error_image_article) { ?>
                <span class="error"><?php echo $error_image_article; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_thumb; ?></td>
              <td><input type="text" name="config_article_thumb_width" value="<?php echo $config_article_thumb_width; ?>" size="3" />
                x
                <input type="text" name="config_article_thumb_height" value="<?php echo $config_article_thumb_height; ?>" size="3" />
                <?php if ($error_image_article_thumb) { ?>
                <span class="error"><?php echo $error_image_article_thumb; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_popup; ?></td>
              <td><input type="text" name="config_article_popup_width" value="<?php echo $config_article_popup_width; ?>" size="3" />
                x
                <input type="text" name="config_article_popup_height" value="<?php echo $config_article_popup_height; ?>" size="3" />
                <?php if ($error_image_article_popup) { ?>
                <span class="error"><?php echo $error_image_article_popup; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_additional; ?></td>
              <td><input type="text" name="config_article_additional_width" value="<?php echo $config_article_additional_width; ?>" size="3" />
                x
                <input type="text" name="config_article_additional_height" value="<?php echo $config_article_additional_height; ?>" size="3" />
                <?php if ($error_image_article_additional) { ?>
                <span class="error"><?php echo $error_image_article_additional; ?></span>
                <?php } ?></td>
            </tr>
            <tr>
              <td><span class="required">*</span> <?php echo $entry_article_related; ?></td>
              <td><input type="text" name="config_article_related_width" value="<?php echo $config_article_related_width; ?>" size="3" />
                x
                <input type="text" name="config_article_related_height" value="<?php echo $config_article_related_height; ?>" size="3" />
                <?php if ($error_image_article_related) { ?>
                <span class="error"><?php echo $error_image_article_related; ?></span>
                <?php } ?></td>
            </tr>
            </table>        
        <h2><?php echo $text_featured_article;?></h2>    
            <table class="form">
              <tr>
                <td style="padding: 0;" colspan="2">
                <select id="category" style="margin-bottom: 5px;" onchange="getArticles();">
                  <?php foreach ($categories as $category) { ?>
                  <option value="<?php echo $category['article_category_id']; ?>"><?php echo $category['name']; ?> <?php echo $category['total']; ?></option>
                  <?php } ?>
                </select></td>
                <td class="left"><?php echo $text_featured_article;?> :</td>
              </tr>
              <tr>
                <td style="padding: 0;"><select multiple="multiple" id="article" size="10" style="width: 350px;">
                  </select></td>
                  <td style="vertical-align: middle;"><input type="button" value="--&gt;" onclick="addFeatured();" />
                  <br />
                  <input type="button" value="&lt;--" onclick="removeFeatured();" /></td>
                  <td style="padding: 0;"><select multiple="multiple" id="featured" size="10" style="width: 350px;">
                </select></td>
              </tr>
            </table>
            <div id="featured_article">
            <?php if($featured_article){?>
              <?php foreach ($featured_article as $featured_id) { ?>
              <input type="hidden" name="featured_article[]" value="<?php echo $featured_id; ?>" />
              <?php } ?>
               <?php } ?>
            </div>
        <h2>Downloads</h2>
         <table class="form">     
            <tr>
              <td><?php echo $entry_upload_allowed; ?></td>
              <td><textarea name="config_news_upload_allowed" cols="40" rows="5"><?php echo $config_news_upload_allowed; ?></textarea></td>
            </tr>   
            <tr>
              <td><?php echo $entry_login_to_download; ?></td>
              <td><?php if ($config_login_to_download) { ?>
                <input type="radio" name="config_login_to_download" value="1" checked="checked" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_login_to_download" value="0" />
                <?php echo $text_no; ?>
                <?php } else { ?>
                <input type="radio" name="config_login_to_download" value="1" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_login_to_download" value="0" checked="checked" />
                <?php echo $text_no; ?>
                <?php } ?></td>
            </tr>       
          </table>
            <table class="form">
          <tr>
            <td><?php echo $entry_free_download; ?></td>
            <td><input type="text" name="download" value="" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><div id="free_download" class="scrollbox">
                <?php $class = 'odd'; ?>
                <?php foreach ($downloads as $download) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div id="free_download<?php echo $download['download_id']; ?>" class="<?php echo $class; ?>"><?php echo $download['name']; ?> <img src="view/image/delete.png" alt="" />
                  <input type="hidden" value="<?php echo $download['download_id']; ?>" />
                </div>
                <?php } ?>
              </div>
              <input type="hidden" name="config_free_download" value="<?php echo $config_free_download; ?>" /></td>
          </tr>
        </table>
        <h2><?php echo $text_comment;?></h2>    
         <table class="form">     
            <tr>
              <td><?php echo $entry_comment; ?></td>
              <td><?php if ($config_comment_status) { ?>
                <input type="radio" name="config_comment_status" value="1" checked="checked" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_comment_status" value="0" />
                <?php echo $text_no; ?>
                <?php } else { ?>
                <input type="radio" name="config_comment_status" value="1" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_comment_status" value="0" checked="checked" />
                <?php echo $text_no; ?>
                <?php } ?></td>
            </tr>
            <tr>
              <td><?php echo $entry_comment_approved; ?></td>
              <td><?php if ($config_comment_approved) { ?>
                <input type="radio" name="config_comment_approved" value="1" checked="checked" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_comment_approved" value="0" />
                <?php echo $text_no; ?>
                <?php } else { ?>
                <input type="radio" name="config_comment_approved" value="1" />
                <?php echo $text_yes; ?>
                <input type="radio" name="config_comment_approved" value="0" checked="checked" />
                <?php echo $text_no; ?>
                <?php } ?></td>
            </tr>
            </table>
            
            </td>            
            </tr>
           
            
          </tbody>          
        </table>
          
          
      </form>
    </div>
  </div>
</div>


<script type="text/javascript"><!--
$('input[name=\'download\']').autocomplete({
	delay: 500,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=news/download/autocomplete&token=<?php echo $token; ?>&filter_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						label: item.name,
						value: item.download_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('#free_download' + ui.item.value).remove();
		
		$('#free_download').append('<div id="free_download' + ui.item.value + '">' + ui.item.label + '<img src="view/image/delete.png" alt="" /><input type="hidden" value="' + ui.item.value + '" /></div>');

		$('#free_download div:odd').attr('class', 'odd');
		$('#free_download div:even').attr('class', 'even');
		
		data = $.map($('#free_download input'), function(element){
			return $(element).attr('value');
		});
						
		$('input[name=\'config_free_download\']').attr('value', data.join());
					
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});

$('#free_download div img').live('click', function() {
	$(this).parent().remove();
	
	$('#free_download div:odd').attr('class', 'odd');
	$('#free_download div:even').attr('class', 'even');

	data = $.map($('#free_download input'), function(element){
		return $(element).attr('value');
	});
					
	$('input[name=\'config_free_download\']').attr('value', data.join());	
});
//--></script> 
<script type="text/javascript"><!--
function addFeatured() {
	$('#article :selected').each(function() {
		$(this).remove();
		
		$('#featured option[value=\'' + $(this).attr('value') + '\']').remove();
		
		$('#featured').append('<option value="' + $(this).attr('value') + '">' + $(this).text() + '</option>');
		
		$('#featured_article input[value=\'' + $(this).attr('value') + '\']').remove();
		
		$('#featured_article').append('<input type="hidden" name="featured_article[]" value="' + $(this).attr('value') + '" />');
	});
}

function removeFeatured() {
	$('#featured :selected').each(function() {
		$(this).remove();
		
		$('#featured_article input[value=\'' + $(this).attr('value') + '\']').remove();
	});
}

function getArticles() {
	$('#article option').remove();
	
	$.ajax({
		url: 'index.php?route=module/article_all_settings/category&token=<?php echo $token; ?>&article_category_id=' + $('#category').attr('value'),
		dataType: 'json',
		success: function(data) {
			for (i = 0; i < data.length; i++) {
	 			$('#article').append('<option value="' + data[i]['article_id'] + '">' + data[i]['name'] + '</option>');
			}
		}
	});
}

function getFeatured() {
	$('#featured option').remove();
	
	$.ajax({
		url: 'index.php?route=module/article_all_settings/featured&token=<?php echo $token; ?>',
		type: 'POST',
		dataType: 'json',
		data: $('#featured_article input'),
		success: function(data) {
			$('#featured_article input').remove();
			
			for (i = 0; i < data.length; i++) {
	 			$('#featured').append('<option value="' + data[i]['article_id'] + '">' + data[i]['name'] + '</option>');
				
				$('#featured_article').append('<input type="hidden" name="featured_article[]" value="' + data[i]['article_id'] + '" />');
			} 
		}
	});
}

getArticles();
getFeatured();
//--></script>
<script type="text/javascript"><!--
$('.breadcrumb .opencartplus').remove();
$('title').html('Easy News Setting');
//--></script> 
<?php echo $footer; ?>